var express = require('express');
var router = express.Router();
var path = require("path");

const BookServices = require("../servers/book/book_servers.js");

const multer = require("multer");

var storage = multer.diskStorage({
  //目标目录
  destination: function(req, file, cb) {
    //绝对路径
    cb(null, path.join(__dirname, "../public/images/upload/"));
  },
  //存储在服务器上的文件命名规则
  filename: function(req, file, cb) {
    //文件后缀
    var ext = file.originalname.slice(file.originalname.lastIndexOf("."));
    cb(null, file.fieldname + "-" + Date.now() + ext);
  }
});

var upload = multer({
  storage: storage
});

//添加职位 完整路径  "api/books/add"
router.post("/add", upload.single("logo"), BookServices.add);

//分页查询职位"/api/books/find_by_page"
router.get("/find_by_page", BookServices.findByPage);

//删除
router.get("/delete", BookServices.deleteById);

//更新
router.post("/update", upload.single("logo"), BookServices.updateById);


module.exports = router;